﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ZXCompany.Models.Entity;
using DBUtil;
using System.Data;
using System.Data.SqlClient;

namespace ZXCompany.Models.Service
{
    public class AccountService
    {
        private SqlConnection sconn =null;
        private Database db = new Database();
        private Dao.DaoFactory DaoFac = new Dao.DaoFactory();

        #region 公司简介        
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void CinfoInsert(ZX_CompanyInfo cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetCInfoDao().Insert(cinfo,sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void CinfoUpdate(ZX_CompanyInfo cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetCInfoDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_CompanyInfo CinfoSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetCInfoDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 公司理念
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void RunIdeaInsert(ZX_RunIdea cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetRunIdea().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void RunIdeaUpdate(ZX_RunIdea cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetRunIdea().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_RunIdea RunIdeaSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetRunIdea().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 公司理念
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void MSpeakInsert(ZX_ManagerSpeak cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetManagerSpeakDao().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void MSpeakUpdate(ZX_ManagerSpeak cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetManagerSpeakDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_ManagerSpeak MSpeakSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetManagerSpeakDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 整体image
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void WholeInfoInsert(ZX_WholeInfo cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetWholeInfoDao().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void WholeInfoUpdate(ZX_WholeInfo cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetWholeInfoDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_WholeInfo WholeInfoSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetWholeInfoDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion
        
        #region 整体战略
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void WholeInfoStrategyInsert(ZX_WholeInfoStrategy cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetWholeInfoStrategyDao().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void WholeInfoStrategyUpdate(ZX_WholeInfoStrategy cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetWholeInfoStrategyDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_WholeInfoStrategy WholeInfoStrategySelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetWholeInfoStrategyDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 品质改善
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void QualityChangeInsert(ZX_QualityChange cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetQualityChangeDao().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void QualityChangeUpdate(ZX_QualityChange cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetQualityChangeDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_QualityChange QualityChangeSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetQualityChangeDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion
        
        #region 精益生产
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void ProductInsert(ZX_Product cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetProductDao().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void ProductUpdate(ZX_Product cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetProductDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_Product ProductSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetProductDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 培训信息
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void TrainInfoInsert(ZX_TrainInfo cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetTrainInfoDao().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void TrainInfoUpdate(ZX_TrainInfo cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetTrainInfoDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_TrainInfo TrainInfoSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetTrainInfoDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 信息技术
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void InfoSkillInsert(ZX_InfoSkill cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetInfoSkillDao().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void InfoSkillUpdate(ZX_InfoSkill cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetInfoSkillDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_InfoSkill InfoSkillSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetInfoSkillDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 联系方式
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void CompanyContactInsert(ZX_CompanyContact cinfo)
        {
            sconn = db.GetConn();
            sconn.Open();
            SqlTransaction stran = sconn.BeginTransaction();
            try
            {
                DaoFac.GetComContactDao().Insert(cinfo, sconn, stran);
                stran.Commit();
            }
            catch (Exception ex)
            {
                stran.Rollback();
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void CompanyContactUpdate(ZX_CompanyContact cinfo)
        {
            sconn = db.GetConn();
            sconn.Open();
            SqlTransaction stran = sconn.BeginTransaction();
            try
            {
                DaoFac.GetComContactDao().Update(cinfo, sconn, stran);
                stran.Commit();
            }
            catch (Exception ex)
            {
                stran.Rollback();
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_CompanyContact CompanyContactSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetComContactDao().SelectTop1(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }

        #endregion

        #region SEO关键字
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void SEOInsert(ZX_SEO cinfo)
        {
            sconn = db.GetConn();
            sconn.Open();
            SqlTransaction stran = sconn.BeginTransaction();
            try
            {
                DaoFac.GetSEODao().Delete(cinfo, sconn, stran);
                DaoFac.GetSEODao().Insert(cinfo, sconn, stran);
                stran.Commit();
            }
            catch (Exception ex)
            {
                stran.Rollback();
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_SEO SEOSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetSEODao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 服务流程
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="cinfo"></param>
        public void SerprocessInsert(ZX_Serprocess cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetSerprocessDao().Insert(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="cinfo"></param>
        public void SerprocessUpdate(ZX_Serprocess cinfo)
        {
            try
            {
                sconn = db.GetConn();
                DaoFac.GetSerprocessDao().Update(cinfo, sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public ZX_Serprocess SerprocessSelect()
        {
            try
            {
                sconn = db.GetConn();
                return DaoFac.GetSerprocessDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        #endregion

        #region 用户管理
        /// <summary>
        /// 获取培训系列图片列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<ZX_User> GetUser()
        {
            SqlConnection sconn = db.GetConn();
            try
            {
                sconn.Open();
                return DaoFac.GetUserDao().Select(sconn);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }

        /// <summary>
        /// 获取培训系列图片列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ZX_User GetUserById(int id)
        {
            SqlConnection sconn = db.GetConn();
            try
            {
                sconn.Open();
                ZX_User extinfo = DaoFac.GetUserDao().SelectByID(id, sconn);
                return extinfo;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }

        /// <summary>
        /// 获取培训系列图片列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ZX_User GetUserByCode(string ucode)
        {
            SqlConnection sconn = db.GetConn();
            try
            {
                sconn.Open();
                ZX_User extinfo = DaoFac.GetUserDao().SelectByCode(ucode, sconn);
                return extinfo;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }

        /// <summary>
        /// 获取培训系列图片列表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ZX_User GetUserLogin(string ucode ,string upawd)
        {
            SqlConnection sconn = db.GetConn();
            try
            {
                sconn.Open();
                ZX_User extinfo = DaoFac.GetUserDao().SelectLogin(ucode, upawd, sconn);
                return extinfo;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }
        /// <summary>
        /// 删除培训系列图片列表
        /// </summary>
        /// <returns></returns>
        public void DeleteUserById(int etid)
        {
            SqlConnection sconn = db.GetConn();
            sconn.Open();
            SqlTransaction stran = sconn.BeginTransaction();
            try
            {
                DaoFac.GetUserDao().Delete(etid, sconn, stran);
                stran.Commit();
            }
            catch (Exception ex)
            {
                stran.Rollback();
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }

        /// <summary>
        /// 更新培训系列图片列表
        /// </summary>
        /// <returns></returns>
        public void UpdateUser(ZX_User zxenty)
        {
            SqlConnection sconn = db.GetConn();
            sconn.Open();
            SqlTransaction stran = sconn.BeginTransaction();
            try
            {
                DaoFac.GetUserDao().Update(zxenty, sconn, stran);
                stran.Commit();
            }
            catch (Exception ex)
            {
                stran.Rollback();
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }

        /// <summary>
        /// 插入培训系列图片列表
        /// </summary>
        /// <returns></returns>
        public void InsertUser(ZX_User zxenty)
        {
            SqlConnection sconn = db.GetConn();
            sconn.Open();
            SqlTransaction stran = sconn.BeginTransaction();
            try
            {
                DaoFac.GetUserDao().Insert(zxenty, sconn, stran);
                stran.Commit();
            }
            catch (Exception ex)
            {
                stran.Rollback();
                throw ex;
            }
            finally
            {
                db.CloseConnection(sconn);
            }
        }        
        #endregion
    }
}